<?php
	require '../defines.php';
	session_start();

	if (!isset($_POST['username']) || !isset($_POST['password'])) myDie("Argumenti za prijavu nisu inicijalizirani!","../index.php");
	
	$username = stringVal($_POST['username']);
	$password = stringVal($_POST['password']);
	
	//if (strlen($username) < 5 || strlen($password) < 5) myDie("Username i password moraju imati barem 5 slova", "../index.php");
		
	$query = "SELECT * FROM korisnik WHERE username='" . $username . "' AND password='" . sha1($password) . "';";
	$result = myQuery($query);
	$row = mysql_fetch_array($result,MYSQL_ASSOC);
	
	if ($row == 0) myDie("Username i/ili password krivi","../index.php");
	
	$_SESSION['id'] = $row['id'];
	$_SESSION['prava'] = $row['prava'];
	header("Location: ../index.php?content=home");
?>